<?php

use App\Helpers\CSRF;
use App\Helpers\HTML;
use App\Helpers\URL;

if ($event !== 'loginAction') { ?>
<?php $app->render('templates/centered_open', ['app' => $app, 'title' => 'Iniciar sesión']) ?>
  <main class="card is-full-width max-w-lg">
    <header>
      <h1>Iniciar sesión</h1>
    </header>
<?php } ?>
    <div id="loginAction">
      <?php if (isset($success)) { ?>
        <?php $app->render('components/success', ['success' => $success]) ?>
      <?php } if (isset($error)) { ?>
        <?php $app->render('components/error', ['error' => $error]) ?>
      <?php } ?>
      <form action="<?= URL::event('login/action', null, 'loginAction') ?>" method="post" target=htmz>
        <input type="hidden" name="<?= CSRF::getVarname() ?>" value="<?= $app->local(CSRF::getVarname()) ?>">
        <p>
          <label for="nickname">Correo / Usuario</label>
          <input type="text" name="nickname" id="nickname" placeholder="Ingresa tu correo o usuario" value="<?= HTML::esc($values['nickname']) ?>" class="<?= $status['nickname'] ?>">
          <small class="text-error"><?= HTML::esc($validations['nickname']) ?></small>
        </p>
        <p>
          <label for="password">Contraseña</label>
          <input type="password" name="password" id="password" placeholder="Ingresa tu contraseña" class="<?= $status['password'] ?>">
          <small class="text-error"><?= HTML::esc($validations['password']) ?></small>
        </p>
        <p>
          <input type="submit" value="Ingresar" class="is-full-width">
        </p>
        <p class="text-center">
          <a href="<?= URL::site('signup') ?>">¿No tienes una cuenta? Regístrate.</a>
        </p>
      </form>
    </div>
<?php if ($event !== 'loginAction') { ?>
  </main>
<?php $app->render('templates/centered_close', ['app' => $app]) ?>
<?php } ?>
